//
// Created by lvyer on 2021/12/2.
//
#include <RendererControl.h>
#include <common/RendererFilter.h>
#include <common/AlphaFilter.h>
#include <common/ScreenFilter.h>
#include <tools/LogTools.h>

RendererControl::RendererControl() {

}

RendererControl::~RendererControl() {

}

void RendererControl::init() {
    //初始化渲染流程，例如创建需要的过滤器列表等，这里先只演示固定创建起始位置的渲染过滤器
    startFilter = new RendererFilter();
    startFilter->initFilter();
    alphaFilter = new AlphaFilter();
    alphaFilter->initFilter();
    screenFilter = new ScreenFilter();
    screenFilter->initFilter();
}

void RendererControl::onSurfaceChanged(int width, int height) {
    //遍历所有过滤器 调用其change方法
    startFilter->changerFilter(width, height);
    alphaFilter->changerFilter(width, height);
    screenFilter->changerFilter(width, height);
}

void RendererControl::draw() {
    //按顺序调用每个过滤器的draw功能
    int textureId = startFilter->drawFilter(0);

    //透明度过滤器
    if (textureId != -1 && isOpenAlpha) {
        textureId = alphaFilter->drawFilter(textureId);
    }
    //高斯模糊过滤器
    //高斯模糊过滤器
    //高斯模糊过滤器
    //高斯模糊过滤器

    if (textureId != -1) {
        screenFilter->drawFilter(textureId);
    }
}


void RendererControl::setAlphaValue(float alphaValue) {
    LOGD("setAlphaValue : %f", alphaValue);
    LOGD("setAlphaValue alphaId : %d", alphaFilter->alphaId);
    alphaFilter->alphaValue = alphaValue;
}